package cn.sdut.training.web.action;

import java.util.List;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;

import cn.sdut.training.domain.User;
import cn.sdut.training.service.UserService;


public class UserAction extends ActionSupport{
	
	private static final long serialVersionUID = 391644418871748706L;
	
	private User user;
	
	private Long id;
	private List<User> userList;
	private Long[] idList;
	
	@Resource
	private UserService userService;
	
	/**
	 * 转到保存页面
	 * @return
	 */
	public String toSavePage(){
		return "toSavePage";
	}
	
	/***
	 * 执行保存方法
	 * @return
	 */
	public String save(){
		userService.saveUser(user);
		return "toList";
	}
	
	/**
	 * 转到列表页面
	 * @return
	 */
	public String toListPage(){
		userList = userService.findAllUser();
		return "toListPage";
	}
	
	/**
	 * 执行删除操作
	 * @return
	 */
	public String delete(){
		for(Long id:idList){
			userService.deleteUser(id);
		}
		return "toList";
	}
	
	/**
	 * 转到编辑页面
	 * @return
	 */
	public String toEditPage(){
		user = userService.getUserById(id);
		return "toEditPage";
	}
	
	/**
	 * 执行更新操作
	 * @return
	 */
	public String update(){
		user.setId(id);
		userService.updateUser(user);
		return "toList";
	}
	
	
	
	//-----------getter和setter方法----------------------
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public Long[] getIdList() {
		return idList;
	}

	public void setIdList(Long[] idList) {
		this.idList = idList;
	}
	
	
}
